package com.mf.controller;

import com.mf.bo.IDs;
import com.mf.entity.Workday;
import com.mf.result.Result;
import com.mf.service.IWorkdayService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;


/**
* <p>
    * 工作日 前端控制器
    * </p>
*
* @author mf
* @since 2024-06-08
*/
@RestController
@RequestMapping("/workday")
public class WorkdayController {
    @Resource
    private IWorkdayService workdayService;

    /**
     * 批量新增工作日
     */
    @PostMapping("/bachAdd")
    @Transactional
    public Result<Integer> bachAdd(@RequestBody IDs workdays)
    {
        final List<Workday> workdaysList =  new ArrayList<>();
        for (int i = 0; i < workdays.getIds().length; i++) {
            final Workday workday = new Workday();
            workday.setDate(workdays.getIds()[i]);
            workdaysList.add(workday);
        }

        workdayService.saveBatch(workdaysList,500);
        return Result.success();
    }
    
    /**
     * 删除工作日
     */
    @GetMapping("/delete")
    public Result<Boolean> delete(@RequestParam("date") String date)
    {
        return Result.success(workdayService.removeById(date));
    }
}
